package com.corn.juc.lock.custome;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author : Jim Wu
 * @version 1.0
 * @function :
 * @since : 2020/12/30 17:02
 */

public class SpinReadWriteLock {

    private AtomicInteger readThread = new AtomicInteger();

    private AtomicInteger writeThread = new AtomicInteger();

    public void readLock() {
        while (writeThread.get() > 0) {

        }
        readThread.getAndIncrement();
    }

    public void readUnlock() {
        readThread.getAndDecrement();
    }

    public void writeLock() {
        writeThread.getAndIncrement();
    }

    public void writeUnlock() {
        writeThread.decrementAndGet();
    }
}
